package cn.edu.xjtu.daily.April.day_4_30;

import java.util.Scanner;

/**
 * @author Hydrion-QLz
 * @date 2022-04-30 18:34
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[][] items = new int[m][2]; // 第一个元素为价格，第二个元素为重要度
        for (int i = 0; i < m; i++) {
            items[i][0] = sc.nextInt();
            items[i][1] = sc.nextInt();
        }
        sc.close();

        int[] dp = new int[n + 1];
        for (int i = 0; i < items.length; i++) {
            for (int j = dp.length - 1; j >= items[i][0]; j--) {
                dp[j] = Math.max(dp[j], dp[j - items[i][0]] + items[i][0] * items[i][1]);
            }
        }
        System.out.println(dp[n]);
    }
}
